package qc.module.cms.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import qc.common.core.exception.QCPromptException;
import qc.module.cms.dto.article.ArticleDto;
import qc.module.cms.dto.statistics.ArticleMultiStatisticsNotMergedRowResultDto;
import qc.module.cms.dto.statistics.ArticleMultiStatisticsResultDto;
import qc.module.cms.dto.statistics.ArticleStatisticsConditionDto;
import qc.module.cms.dto.statistics.ArticleStatisticsResultDto;
import qc.module.cms.service.StatisticsService;

import java.util.List;

/**
 * @projectName: qcdp
 * @package: qc.module.cms.api.controller
 * @className: StatisticsController
 * @date: 2023/7/31
 * @version: 1.0
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    private StatisticsService statisticsService;

    @Autowired
    public void setStatisticsService(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }


    /**
     * 统计指定时间段、指定栏目中发布文章情况，按作者和部门统计
     *
     * @param condition: 查询条件
     * @return ArticleStatisticsResultDto 查询结果
     * @author QcCheng Tech
     * @date 2023/8/1
     */
    @RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
    public ArticleStatisticsResultDto query(@RequestBody ArticleStatisticsConditionDto condition) throws QCPromptException {
        return statisticsService.query(condition);
    }

    /**
     * 指定作者查询文章数量
     *
     * @param condition: 查询条件
     * @return List<ArticleDto> 查询结果
     * @author QcCheng Tech
     * @date 2023/8/1
     */
    @RequestMapping(value = "/author", method = {RequestMethod.GET, RequestMethod.POST})
    public List<ArticleDto> queryByAuthor(@RequestBody ArticleStatisticsConditionDto condition) throws QCPromptException {
        return statisticsService.queryArticleCountByDeptOrAuthor(condition,true);
    }

    /**
     * 指定部门查询文章数量
     *
     * @param condition: 查询条件
     * @return List<ArticleDto> 查询结果
     * @author QcCheng Tech
     * @date 2023/8/1
     */
    @RequestMapping(value = "/dept", method = {RequestMethod.GET, RequestMethod.POST})
    public List<ArticleDto> queryByDept(@RequestBody ArticleStatisticsConditionDto condition) throws QCPromptException {
        return statisticsService.queryArticleCountByDeptOrAuthor(condition, false);
    }

    /**
     * 统计指定时间段、指定栏目中发布文章情况，按发布人统计结果和按部门统计结果；
     * 发布人统计包含文章列表和排名前5（其他的合并显示为其他）；
     * 部门统计按部门进行分类，每个部门中显示发文的发布人名称和文章数量；
     *
     * @param condition: 查询条件
     * @return ArticleMultiStatisticsResultDto 查询结果
     * @author QcCheng Tech
     * @date 2023/11/8
     */
    @RequestMapping(value = "/sts", method = {RequestMethod.GET, RequestMethod.POST})
    public ArticleMultiStatisticsResultDto statisticsByInUserAndDept(@RequestBody ArticleStatisticsConditionDto condition) throws QCPromptException {
        return statisticsService.statisticsByInUserAndDept(condition);
    }

    /**
     * 按发布人和发布部门统计文章结果转为未合并处理的单条数据集合对象
     *
     * @param condition
     * @return
     * @throws QCPromptException
     */
    @RequestMapping(value = "/stsnotmergedrow", method = {RequestMethod.GET, RequestMethod.POST})
    public ArticleMultiStatisticsNotMergedRowResultDto statisticsByInUserAndDeptNotMerged(@RequestBody ArticleStatisticsConditionDto condition) throws QCPromptException {
        return statisticsService.statisticsByInUserAndDeptNotMergedRow(condition);
    }

}
